package com.qzsoft.zhjd.server.modules.cement.handler;

import java.util.Date;

import com.qzsoft.zhjd.server.modules.cement.entity.CollectCementDataEntity;
import com.qzsoft.zhjd.server.modules.cement.entity.CollectCementDataWeightEntity;
import com.qzsoft.zhjd.server.modules.cement.entity.CollectCementMatchEntity;
import com.qzsoft.zhjd.server.modules.cement.model.CementCollectDataModel;

/**
 * @ClassName CementDataHandler
 * @Description 生产主表处理
 * @author linhuawei
 * @since 2022-02-28
 */
public class CementDataHandler {

    /**
     * @Title coverTo
     * @Description 生产主表处理
     * @param originalData
     * @param match
     * @param dataWeight
     * @return
     */
    public static CollectCementDataEntity coverTo(CementCollectDataModel originalData, CollectCementMatchEntity match,
                                                  CollectCementDataWeightEntity dataWeight) {
        CollectCementDataEntity data = new CollectCementDataEntity();
        if (null != match) {
            data.setBaseCode(match.getBaseCode());
            data.setProjectId(match.getProjectId());
            data.setStationCode(match.getStationCode());
            data.setMatchCode(match.getMatchCode());
        } else {
            String baseCode = null;
            String stationCode = originalData.getStationCode();
            // JD##CSB#
            if (8 == stationCode.length()) {
                baseCode = stationCode.substring(0, 4);
            }
            data.setBaseCode(baseCode);
            data.setStationCode(originalData.getStationCode());
            data.setMatchCode(originalData.getMatchCode());
        }
        data.setBatchWeight(dataWeight.getBatchWeight());
        data.setOriginalId(originalData.getId());
        data.setDischargeTime(originalData.getDischargeTime());
        data.setInsertTime(new Date());
        return data;
    }

}
